(function ($) {
    var tab=function(box,opt){
        /*console.log(opt)
        console.log(box)*/
        this.box=box;
        this.options=$.extend({},tab.defaults,opt);
        /*console.log(this.options)*/
        this.index=0;
        // console.log($("."+this.options.yemian).length)
        if($("."+this.options.tab).length=$("."+this.options.yemian).length){
            $("."+this.options.tab).bind(this.options.event, {"options":this.options,"index":this.index},this.method);
        }
        // var listlen=this.list.length,
        //     targetlen=$("."+this.options.tabtarget).length;
        // if(listlen==targetlen) $(this.list).bind("click",{"options":this.options},this.method)
    }
    
    tab.defaults={
        tab:"tab",
        tabactive:"tab_active",
        yemian:"yemian",
        yemianactive:"active",
        event:"click"
    }
    tab.prototype={
        method:function(options){
            var opt=options.data.options;
            $("."+opt.tab).eq(options.data.index).removeClass(opt.tabactive);
            $(this).addClass(opt.tabactive);
            $("."+opt.yemian).eq(options.data.index).removeClass(opt.yemianactive);
            $("."+opt.yemian).eq($(this).index()-1).addClass(opt.yemianactive);
            options.data.index=$(this).index()-1;
        }
    }
    
    function plguin(options){
        return this.each(function () {
            var otab = new tab(this,options);
            /*console.log(this)*/
        })
    }
    
    $.fn.tab=plguin;
    
})(jQuery);